package nl.hu.verbrandendephoenix.view;

import java.util.ArrayList;
import java.util.Date;

import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.datepicker.client.DateBox;

public class EditProfile {

	private Grid grdProfileForm;
	private VerticalPanel pnlProfileForm, pnlGender;
	private Label lblUsername, lblFirstName, lblNamePrefix, lblLastname, lblGender, lblDateOfBirth, lblHomePhone, lblWorkPhone, lblStreet, lblStreetNumber,
	lblStreetNumberAdd, lblCity, lblZipCode;
	private TextBox txtNamePrefix, txtFirstName, txtLastName, txtHomePhone, txtWorkPhone, txtStreet, txtStreetNumber, txtStreetNumberAdd, txtCity, txtZipCode;
	private DateBox txtDateOfBirth;
	private RadioButton rbtnMale, rbtnFemale;
	private Button btnConfirm;

	public EditProfile() {
		pnlProfileForm = new VerticalPanel();
	}

	public Panel constructForm() {
		//Profiel wijzigen panel		
		grdProfileForm = new Grid(13,4);

		Label title = new Label("Wijzig Gegevens:");
		title.addStyleName("h1");
		pnlProfileForm.add(title);
		
		lblUsername = new Label();

		grdProfileForm.setWidget(0, 0, lblUsername);

		lblFirstName = new Label("Naam:");
		lblNamePrefix = new Label("Tussenvoegsel:");
		lblLastname = new Label("Achternaam:");
		
		grdProfileForm.setWidget(1, 0, lblFirstName);
		grdProfileForm.setWidget(1, 1, lblNamePrefix);
		grdProfileForm.setWidget(1, 2, lblLastname);
		
		txtFirstName = new TextBox();
		txtNamePrefix = new TextBox();
		txtLastName = new TextBox();
		
		grdProfileForm.setWidget(2, 0, txtFirstName);
		grdProfileForm.setWidget(2, 1, txtNamePrefix);
		grdProfileForm.setWidget(2, 2, txtLastName);
		
		lblGender = new Label("Geslacht:");
		lblDateOfBirth = new Label("Geboortedatum:");
		
		grdProfileForm.setWidget(3, 0, lblGender);
		grdProfileForm.setWidget(3, 1, lblDateOfBirth);

		pnlGender = new VerticalPanel();
		rbtnMale = new RadioButton("Gender", "Male");
		rbtnFemale = new RadioButton("Gender", "Female");
		pnlGender.add(rbtnMale);
		pnlGender.add(rbtnFemale);
		
		txtDateOfBirth = new DateBox();
		txtDateOfBirth.setFormat(new DateBox.DefaultFormat(DateTimeFormat.getFormat("d/M/y")));

		grdProfileForm.setWidget(4, 0, pnlGender);
		grdProfileForm.setWidget(4, 1, txtDateOfBirth);

		lblHomePhone = new Label("Telefoonnummer thuis:");
		lblWorkPhone = new Label("Telefoonnummer werk:");

		grdProfileForm.setWidget(5, 0, lblHomePhone);
		grdProfileForm.setWidget(5, 1, lblWorkPhone);

		txtHomePhone = new TextBox();
		txtWorkPhone = new TextBox();

		grdProfileForm.setWidget(6, 0, txtHomePhone);
		grdProfileForm.setWidget(6, 1, txtWorkPhone);

		lblStreet = new Label("Straat:");
		lblStreetNumber = new Label("Huisnummer:");
		lblStreetNumberAdd = new Label("toevoeging:");
		
		grdProfileForm.setWidget(7, 0, lblStreet);
		grdProfileForm.setWidget(7, 1, lblStreetNumber);
		grdProfileForm.setWidget(7, 2, lblStreetNumberAdd);
		
		

		txtStreet = new TextBox();
		txtStreetNumber = new TextBox();
		txtStreetNumberAdd = new TextBox();
		
		grdProfileForm.setWidget(8, 0, txtStreet);
		grdProfileForm.setWidget(8, 1, txtStreetNumber);
		grdProfileForm.setWidget(8, 2, txtStreetNumberAdd);

		lblZipCode = new Label("Postcode:");
		lblCity = new Label("Stad:");
		
		grdProfileForm.setWidget(9, 0, lblZipCode);
		grdProfileForm.setWidget(9, 1, lblCity);

		txtZipCode = new TextBox();
		txtCity = new TextBox();
		
		grdProfileForm.setWidget(10, 0, txtZipCode);
		grdProfileForm.setWidget(10, 1, txtCity);

		btnConfirm = new Button("Verzenden");
		grdProfileForm.setWidget(11, 0, btnConfirm);
		
		pnlProfileForm.add(grdProfileForm);

		return pnlProfileForm;
	}
	
	public ArrayList<TextBox> getArrTextBox() {
		ArrayList<TextBox> arrTextBox = new ArrayList<TextBox>();
		arrTextBox.add(txtFirstName);
		arrTextBox.add(txtLastName);
		//arrTextBox.add(txtDateOfBirth);
		arrTextBox.add(txtHomePhone);
		arrTextBox.add(txtWorkPhone);
		arrTextBox.add(txtStreet);
		arrTextBox.add(txtStreetNumber);
		arrTextBox.add(txtStreetNumberAdd);
		arrTextBox.add(txtCity);
		arrTextBox.add(txtZipCode);
		return arrTextBox;
	}
	
	public Button getBtnConfirm() {
		return btnConfirm;
	}
	
	public Label getLblUsername() {
		return lblUsername;
	}
	
	public TextBox getTxtFirstName() {
		return txtFirstName;
	}
	
	public TextBox getTxtNamePrefix () {
		return txtNamePrefix;
	}
	
	public TextBox getTxtLastName() {
		return txtLastName;
	}
	
	public int getGender() {
		if(rbtnMale.getValue()) {
			return 1;
		} else if(rbtnFemale.getValue()) {
			return 2;
		} else {
			return 0;
		}
	}
	
	public TextBox getTxtHomePhone() {
		return txtHomePhone;
	}
	
	public TextBox getTxtWorkPhone() {
		return txtWorkPhone;
	}
	
	public TextBox getTxtStreet() {
		return txtStreet;
	}
	
	public TextBox getTxtStreetNumber() {
		return txtStreetNumber;
	}
	
	public TextBox getTxtStreetNumberAdd() {
		return txtStreetNumberAdd;
	}
	
	public TextBox getTxtCity() {
		return txtCity;
	}
	
	public TextBox getTxtZipCode() {
		return txtZipCode;
	}
	
	public DateBox getTxtDateOfBirth() {
		return txtDateOfBirth;
	}
	/**
	 * Setters
	 */
	public void setUsername(String uName) {
		this.lblUsername.setText(uName);
	}
	public void setFirstName(String firstName) {
		this.txtFirstName.setText(firstName);
	}
	public void setNamePrefix(String namePrefix) {
		this.txtNamePrefix.setText(namePrefix);
	}
	public void setLastName(String lastName) {
		this.txtLastName.setText(lastName);
	}
	public void setGender(int i) {
		if(i == 1) { 
			rbtnMale.setValue(true);
		} else if(i == 2) {
			rbtnFemale.setValue(true);
		}
	}
	public void setDateOfBirth(Date date) {
		this.txtDateOfBirth.setValue(date);
	}
	public void setHomePhone(String homePhone) {
		this.txtHomePhone.setText(homePhone);
	}
	public void setWorkPhone(String workPhone) {
		this.txtWorkPhone.setText(workPhone);
	}
	public void setStreet(String street) {
		this.txtStreet.setText(street);
	}
	public void setStreetNumber(String streetNumber) {
		this.txtStreetNumber.setText(streetNumber);
	}
	public void setStreetNumberAdd(String streetNumberAdd) {
		this.txtStreetNumberAdd.setText(streetNumberAdd);
	}
	public void setCity(String city) {
		this.txtCity.setText(city);
	}
	public void setZipCode(String zipCode) {
		this.txtZipCode.setText(zipCode);
	}
}